local hx__gulei = fk.CreateSkill {
  name = "hx__gulei",
}

hx__gulei:addEffect(fk.DamageCaused, {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(hx__gulei.name) and data.skillName ~= hx__gulei.name
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = hx__gulei.name,
      prompt = "是否发动【固垒】将你即将造成的"..data.damage.."点伤害改为依次造成1点伤害？",
    })
  end,
  on_use = function(self, event, target, player, data)
    local x = data.damage
    data:preventDamage()
    for i = 1, x do
      player.room:damage({
        from = player,
        to = data.to,
        damage = 1,
        skillName = hx__gulei.name,
      })
    end
  end,
})


hx__gulei:addEffect(fk.DamageInflicted, {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(hx__gulei.name) and data.skillName ~= hx__gulei.name
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = hx__gulei.name,
      prompt = "是否发动【固垒】将你即将受到的"..data.damage.."点伤害改为依次受到1点伤害？",
    })
  end,
  on_use = function(self, event, target, player, data)
    local x = data.damage
    data:preventDamage()
    for i = 1, x do
      player.room:damage({
        from = data.from,
        to = player,
        damage = 1,
        skillName = hx__gulei.name,
      })
    end
  end,
})


hx__gulei:addEffect(fk.BeforeDrawCard, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__gulei.name) and data.num > 1
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = hx__gulei.name,
      prompt = "是否发动【固垒】将你即将获得的"..data.num.."张牌改为依次获得1张牌？",
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local x = data.num
    data.num = 0
    for i = 1, x do
      player:drawCards(1, hx__gulei.name)
    end
  end,
})


return hx__gulei
